home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6639 / 6639.xpi / chrome / easydragtogo.jar / content / easydragtogo.js next >
Text File  |  2009-06-14  |  21KB  |  606 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Easy DragToGo code.
  15.  *
  16.  * The Initial Developer of the Original Code is Sunwan.
  17.  * Portions created by the Initial Developer are Copyright (C) 2008
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Sunwan <SunwanCN@gmail.com>
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  25.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. var easyDragToGo = {
  38.  
  39.   loaded: false,
  40.   moving: false,
  41.   StartAlready: false,
  42.   onStartEvent: null,       // drag start event
  43.   onDropEvent: null,        // drag drop event
  44.   aXferData: null,          // drag data
  45.   aDragSession: null,       // drag session
  46.   timeId: null,
  47.  
  48.   onLoad: function() {
  49.     if (!easyDragToGo.loaded) {
  50.       var contentArea = getBrowser().mPanelContainer;
  51.       if (contentArea) {
  52.         try {
  53.           eval("nsDragAndDrop.dragOver =" + nsDragAndDrop.dragOver.toString().replace(
  54.             'aEvent.stopPropagation();',
  55.             'if ( !easyDragToGo.moving ) { $& }')
  56.           );
  57.         } catch(e) {}
  58.         eval("nsDragAndDrop.checkCanDrop =" + nsDragAndDrop.checkCanDrop.toString().replace(
  59.           'if ("canDrop" in aDragDropObserver)',
  60.           'if (easyDragToGo.StartAlready) this.mDragSession.canDrop = true; $&')
  61.         );
  62.         contentArea.addEventListener('draggesture', function(e) {easyDragToGo.dragStart(e)}, true);
  63.         contentArea.addEventListener('dragover', function(e) {
  64.             easyDragToGo.moving = true;
  65.             nsDragAndDrop.dragOver(e, easyDragToGoDNDObserver);
  66.             easyDragToGo.moving = false;
  67.           }, false);
  68.         contentArea.addEventListener('dragdrop', function(e) {
  69.             nsDragAndDrop.drop(e, easyDragToGoDNDObserver);
  70.           }, false);
  71.         contentArea.addEventListener('drop', function(e) {
  72.             nsDragAndDrop.drop(e, easyDragToGoDNDObserver);
  73.           }, false);
  74.       }
  75.       easyDragToGo.loaded = true;
  76.     }
  77.   },
  78.  
  79.   dragStart: function(aEvent) {
  80.     this.onStartEvent = aEvent;
  81.     this.StartAlready = true;
  82.     this.setTimeout();
  83.   },
  84.  
  85.   clean: function() {
  86.     this.StartAlready = false;
  87.     if (this.onDropEvent) {
  88.       this.onDropEvent.preventDefault();
  89.       this.onDropEvent.stopPropagation();
  90.     }
  91.     this.onStartEvent = this.onDropEvent = this.aXferData = this.aDragSession = null;
  92.   },
  93.  
  94.   setTimeout: function() {
  95.     var timeout = easyDragUtils.getPref("timeout", 0);
  96.     if (timeout > 0) {
  97.       clearTimeout(this.timeId);
  98.       this.timeId = setTimeout(function(){easyDragToGo.clean()}, timeout);
  99.     }
  100.   },
  101.  
  102.   openURL: function(aURI, src, target, X, Y) {
  103.     if (!aURI) return;
  104.  
  105.     var act = "";
  106.  
  107.     if (target.indexOf("fromContentOuter") == -1) {
  108.  
  109.       var actionSets = easyDragUtils.getPref(target + ".actionSets", "|");
  110.  
  111.       if (!actionSets || actionSets == "|") return;
  112.  
  113.       var dir;
  114.       var directions = actionSets.split('|')[0];
  115.  
  116.       switch (directions) {
  117.         case "A":
  118.           // any direction
  119.           dir = "A";
  120.           break;
  121.         case "UD":
  122.           // up and down
  123.           dir = (Y > 0) ? "D" : "U";
  124.           break;
  125.         case "RL":
  126.           // right and left
  127.           dir = (X > 0) ? "R" : "L";
  128.           break;
  129.         case "RLUD":
  130.           // right left up down
  131.           if ( X > Y )
  132.             ( X + Y > 0 ) ? (dir = "R") : (dir = "U");
  133.           else
  134.             ( X + Y > 0 ) ? (dir = "D") : (dir = "L");
  135.           break;
  136.         default:
  137.           return;
  138.       }
  139.  
  140.       var re = new RegExp(dir + ':(.+?)(\\s+[ARLUD]:|$)', '');
  141.       try { if ( re.test(actionSets) ) act = RegExp.$1; } catch(e) {}
  142.     }
  143.     else {
  144.       act = easyDragUtils.getPref(target, "link-fg");
  145.     }
  146.  
  147.     if (!act) return;
  148.  
  149.     var browser = getTopWin().getBrowser();
  150.     var uri = "";
  151.     var bg = true;
  152.     var postData = {};
  153.  
  154.     // get search strings
  155.     if ((target == "text" || target == "fromContentOuter.text") && act.indexOf("search-") == 0) {
  156.       var submission = this.getSearchSubmission(aURI, act);
  157.       if (submission) {
  158.         uri = submission.uri.spec;
  159.         postData.value = submission.postData;
  160.         if (uri && /(fg|bg|cur)$/.test(act))
  161.           act = "search-" + RegExp.$1;
  162.         else
  163.           act = "";
  164.       }
  165.       else
  166.         act = "";
  167.       if (!act) alert("No Search Engines!");
  168.     }
  169.  
  170.     switch (act) {
  171.       case "search-fg":
  172.       case "link-fg":
  173.         // open a new tab and selected it
  174.         bg = false;
  175.       case "search-bg":
  176.       case "link-bg":
  177.         if (!uri) uri = getShortcutOrURI(aURI, postData);
  178.         try {
  179.           var cur = (!bg || browser.mTabs.length == 1) &&
  180.                 browser.webNavigation.currentURI.spec == "about:blank" &&
  181.                 !browser.mCurrentBrowser.webProgress.isLoadingDocument ||
  182.                 (/^(javascript|mailto):/i.test(uri));
  183.         } catch(e) {}
  184.         if (cur)
  185.           // open in current tab
  186.           loadURI(uri, null, postData.value, true);
  187.         else {
  188.           // for Tree Style Tab extension
  189.           if ("TreeStyleTabService" in window && (target == "link" && !this.aDragSession.sourceNode.localName || target == "img"))
  190.             try {TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab);} catch(e) {}
  191.  
  192.           // open a new tab
  193.           browser.loadOneTab(uri, null, null, postData.value, bg, true);
  194.         }
  195.         break;
  196.  
  197.       case "search-cur":
  198.       case "link-cur":
  199.         // open in current
  200.         if (!uri) uri = getShortcutOrURI(aURI, postData);
  201.         loadURI(uri, null, postData.value, true);
  202.         break;
  203.  
  204.       case "save-link":
  205.         // save links as...
  206.         if ("PlacesUtils" in window) {  // firefox 3 and above
  207.           var aLink = this.onStartEvent.target;
  208.           document.popupNode = aLink;
  209.           var contextMenu = new nsContextMenu(aLink, browser);
  210.           contextMenu.saveLink();
  211.         }
  212.         else {
  213.           var doc = this.onStartEvent.target.ownerDocument;
  214.           saveURL(aURI, null, null, true, false, makeURI(doc.location.href, doc.characterSet));
  215.         }
  216.         break;
  217.  
  218.       case "img-fg":
  219.         // open imgs in new tab and selected it
  220.         bg = false;
  221.       case "img-bg":
  222.         // for Tree Style Tab extension
  223.         if ("TreeStyleTabService" in window && target == "img")
  224.           try {TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab);} catch(e) {}
  225.         // open imgs in new tab
  226.         browser.loadOneTab(src, null, null, null, bg);
  227.         break;
  228.  
  229.       case "img-cur":
  230.         // open imgs in current
  231.         loadURI(src, null, null, false);
  232.         break;
  233.  
  234.       case "save-img":
  235.         // save imgs as...
  236.         saveImageURL(src, null, null, false, false, browser.currentURI);
  237.         break;
  238.  
  239.       case "save-df-img":
  240.         // direct save imgs to folder
  241.         var err = this.saveimg(src);
  242.         if (err) alert("Saving image failed: " + err);
  243.         break;
  244.  
  245.       default:
  246.         // for custom
  247.         if (/^custom#(.+)/.test(act)) {
  248.           var custom = RegExp.$1;
  249.           if (custom) {
  250.             var code = easyDragUtils.getPref("custom." + custom, "return");
  251.             if (code) {
  252.               try {
  253.                 this.customCode(code, aURI, src, target, X, Y);
  254.               }
  255.               catch(e) {
  256.                 alert("Easy DragToGo: Custom(" + custom + ") Error: " + e + "\n");
  257.               }
  258.             }
  259.           }
  260.         }
  261.         // do nothing
  262.         break;
  263.     }
  264.   },
  265.  
  266.   customCode: function(code, url, src, target, X, Y) {
  267.     eval(code);
  268.   },
  269.  
  270.   getSearchSubmission: function(searchStr, action) {
  271.     try {
  272.       var ss = Components.classes["@mozilla.org/browser/search-service;1"]
  273.                 .getService(Components.interfaces.nsIBrowserSearchService);
  274.       var engine, engineName;
  275.       if ( /^search-(.+?)-?(fg|bg|cur)$/.test(action) )
  276.         engineName = RegExp.$1;
  277.       else
  278.         engineName = "c";
  279.  
  280.       if ( engineName == "c" )
  281.         engine = ss.currentEngine || ss.defaultEngine;
  282.       else if ( engineName == "d" )
  283.         engine = ss.defaultEngine || ss.currentEngine;
  284.       else {
  285.         engine = ss.getEngineByName(engineName);
  286.         if (!engine) engine = ss.currentEngine || ss.defaultEngine;
  287.       }
  288.       return engine.getSubmission(searchStr, null);
  289.     }
  290.     catch (e) {
  291.       return null;
  292.     }
  293.   },
  294.  
  295.   saveimg: function(aSrc) {
  296.     if (!aSrc) return "No Src!";
  297.  
  298.     if ( /^file\:\/\/\//.test(aSrc) ) return "Local image, does not need save!";
  299.  
  300.     var path = easyDragUtils.getDownloadFolder();
  301.     var fileName;
  302.  
  303.     try {
  304.       var imageCache = Components.classes['@mozilla.org/image/cache;1'].getService(imgICache);
  305.       var props = imageCache.findEntryProperties(makeURI(aSrc, getCharsetforSave(null)));
  306.       if (props)
  307.         fileName = props.get("content-disposition", nsISupportsCString).toString().
  308.                    replace(/^.*?filename=(["']?)(.+)\1$/, '$2');
  309.     } catch (e) {}
  310.  
  311.     if (!fileName) fileName = aSrc.substr( aSrc.lastIndexOf('/') + 1 );
  312.     if (fileName) fileName = fileName.replace(/\?.*/, "").replace(/[\\\/\*\|:"<>]/g, "-");
  313.     if (!fileName) return "No image!";
  314.     var fileSaving = Components.classes["@mozilla.org/file/local;1"].
  315.                      createInstance(Components.interfaces.nsILocalFile);
  316.     fileSaving.initWithPath(path);
  317.     if ( !fileSaving.exists() || !fileSaving.isDirectory() )
  318.       return "The download folder does not exist!";
  319.  
  320.     // create a subdirectory with the domain name of current page
  321.     if ( easyDragUtils.getPref("saveDomainName", true) ) {
  322.       var domainName = getTopWin().getBrowser().currentURI.host;
  323.       if (domainName) {
  324.         fileSaving.append(domainName);
  325.         if ( !fileSaving.exists() || !fileSaving.isDirectory() ) {
  326.           try {
  327.             fileSaving.create(1, 0755); // 1: DIRECTORY_TYPE
  328.           }
  329.           catch(e) {
  330.             return "Create directory failed!";
  331.           }
  332.         }
  333.         path = fileSaving.path;
  334.       }
  335.     }
  336.  
  337.     fileSaving.append(fileName);
  338.  
  339.     // does not overwrite the original file
  340.     var newFileName = fileName;
  341.     while ( fileSaving.exists() ) {
  342.       if ( newFileName.indexOf('.') != -1 ) {
  343.         var ext = newFileName.substr(newFileName.lastIndexOf('.'));
  344.         var file = newFileName.substring(0, newFileName.length - ext.length);
  345.         newFileName = this.getAnotherName(file) + ext;
  346.       }
  347.       else
  348.         newFileName = this.getAnotherName(newFileName);
  349.       fileSaving.initWithPath(path);
  350.       fileSaving.append(newFileName);
  351.     }
  352.  
  353.     var cacheKey  = Components.classes['@mozilla.org/supports-string;1'].
  354.                     createInstance(Components.interfaces.nsISupportsString);
  355.     cacheKey.data = aSrc;
  356.  
  357.     var urifix  = Components.classes['@mozilla.org/docshell/urifixup;1'].
  358.                   getService(Components.interfaces.nsIURIFixup);
  359.     var uri     = urifix.createFixupURI(aSrc, 0);
  360.     var hosturi = null;
  361.     if ( uri.host.length > 0 )
  362.       hosturi = urifix.createFixupURI(uri.host, 0);
  363.  
  364.     var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].
  365.                   createInstance(Components.interfaces.nsIWebBrowserPersist);
  366.     persist.persistFlags = Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_FROM_CACHE |
  367.                            Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_CLEANUP_ON_FAILURE;
  368.     persist.saveURI(uri, cacheKey, hosturi, null, null, fileSaving);
  369.     if (persist.result) return "Can not save image or get image failed!";
  370.  
  371.     function StatusLabel() {
  372.       var SaveLabel = "The image(" + newFileName + ") has been saved to "+ path;
  373.       document.getElementById('statusbar-display').label = SaveLabel;
  374.     }
  375.     setTimeout(StatusLabel,100);
  376.     return 0;
  377.   },
  378.  
  379.   // filenameNoExt -> filenameNoExt[1] -> filenameNoExt[2] ...
  380.   getAnotherName: function(fName) {
  381.     if ( /\[(\d+)\]$/.test(fName) ) {
  382.       var i = 1 + parseInt(RegExp.$1);
  383.       fName = fName.replace(/\[\d+\]$/, "[" + i + "]");
  384.     }
  385.     else
  386.       fName += "[1]";
  387.     return fName;
  388.   },
  389.  
  390.   SelectedText: function(node) {
  391.     if (!node) return "";
  392.     if ( node.localName == "TEXTAREA" || (node.localName == "INPUT" && node.type == "text") )
  393.       return node.value.substring(node.selectionStart, node.selectionEnd);
  394.     else
  395.       return document.commandDispatcher.focusedWindow.getSelection().toString();
  396.   },
  397.  
  398.   seemAsURL: function(url) {
  399.       // url test
  400.       var DomainName = /(\w+(\-+\w+)*\.)+\w{2,7}/;
  401.       var HasSpace = /\S\s+\S/;
  402.       var KnowNameOrSlash = /^(www|bbs|forum|blog)|\//;
  403.       var KnowTopDomain1 = /\.(com|net|org|gov|edu|info|mobi|mil|asia)$/;
  404.       var KnowTopDomain2 = /\.(de|uk|eu|nl|it|cn|be|us|br|jp|ch|fr|at|se|es|cz|pt|ca|ru|hk|tw|pl)$/;
  405.       var IsIpAddress = /^([1-2]?\d?\d\.){3}[1-2]?\d?\d/;
  406.       var seemAsURL = !HasSpace.test(url) && DomainName.test(url) &&
  407.                        (KnowNameOrSlash.test(url) || KnowTopDomain1.test(url) ||
  408.                         KnowTopDomain2.test(url) || IsIpAddress.test(url));
  409.       return seemAsURL;
  410.   },
  411.  
  412.   getForceURL: function(url) {
  413.     var code;
  414.     var str = "";
  415.     url = url.replace(/\s|\r|\n|\u3000/g, "");
  416.     for (var i = 0; i < url.length; i++) {
  417.       code = url.charCodeAt(i);
  418.       if (code >= 65281 && code <= 65373)
  419.         str += String.fromCharCode(code - 65248);
  420.       else
  421.         str += url.charAt(i);
  422.     }
  423.     str = this.fixupSchemer(str);
  424.     str = this.SecurityCheckURL(str);
  425.     return str;
  426.   },
  427.  
  428.   SecurityCheckURL: function(aURI) {
  429.     if ( /^data:/.test(aURI) ) return "";
  430.     if ( /^javascript:/.test(aURI) ) return aURI;
  431.     var sourceURL = getBrowser().currentURI.spec;
  432.     const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
  433.     var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
  434.                   .getService(nsIScriptSecurityManager);
  435.     const nsIScriptSecMan = Components.interfaces.nsIScriptSecurityManager;
  436.     try {
  437.       secMan.checkLoadURIStr(sourceURL, aURI, nsIScriptSecMan.STANDARD);
  438.     } catch(e) {
  439.       aURI = "";
  440.     }
  441.     return aURI;
  442.   },
  443.  
  444.   fixupSchemer: function(aURI) {
  445.     if ( /^(?::\/\/|\/\/|\/)?(([1-2]?\d?\d\.){3}[1-2]?\d?\d(\/.*)?|[a-z]+[\-\w]+\.[\-\w\.]+(\/.*)?)$/i.test(aURI) )
  446.       aURI = "http://" + RegExp.$1;
  447.     else if ( /^\w+[\-\.\w]*@(\w+(\-+\w+)*\.)+\w{2,7}$/.test(aURI) )
  448.       aURI = "mailto:" + aURI;
  449.     else {
  450.       var table = "ttp=>http,tp=>http,p=>http,ttps=>https,tps=>https,ps=>https,s=>https";
  451.       var regexp = new RegExp();
  452.       if (aURI.match(regexp.compile('^('+ table.replace(/=>[^,]+|=>[^,]+$/g, '').replace(/\s*,\s*/g, '|')+'):', 'g'))) {
  453.         var target = RegExp.$1;
  454.         table.match(regexp.compile('(,|^)'+target+'=>([^,]+)'));
  455.         aURI = aURI.replace(target, RegExp.$2);
  456.       }
  457.     }
  458.     return aURI;
  459.   }
  460. }; 
  461.  
  462. var easyDragToGoDNDObserver = {
  463.  
  464.   onDragOver: function(aEvent, aFlavour, aDragSession) {
  465.     aDragSession.canDrop = true;
  466.     // for drag tabs or bookmarks
  467.     if (!easyDragToGo.StartAlready) {
  468.       easyDragToGo.onStartEvent = aEvent;
  469.       easyDragToGo.StartAlready = true;
  470.       easyDragToGo.setTimeout();
  471.     }
  472.   },
  473.  
  474.   onDrop: function(aEvent, aXferData, aDragSession) {
  475.     if (!easyDragToGo.StartAlready) return;
  476.     easyDragToGo.onDropEvent = aEvent;
  477.     easyDragToGo.aXferData = aXferData;
  478.     easyDragToGo.aDragSession = aDragSession;
  479.  
  480.     var sNode = aDragSession.sourceNode;
  481.     var url;
  482.     if ( !sNode ) {
  483.       // Drag and Drop from content outer
  484.       try {url = aXferData.data.replace( /^[\s\n]+|[\s\n]+$/g, '' )} catch(e) {}
  485.       if (!url) {
  486.         easyDragToGo.clean();
  487.         return;
  488.       }
  489.       var target = "fromContentOuter.text";
  490.       if ( easyDragToGo.seemAsURL(url) || (/^file:\/\/\/[\S]+$/.test(url)) ) {
  491.         //force it to a url or local file/directory
  492.         if ( /^file:\/\/\//.test(url)) {
  493.           if ( /([^\/]+\.(xpi|jar))$/.test(url) ) {
  494.             eval("InstallTrigger.install({ '" + RegExp.$1 + "' : url })");
  495.             easyDragToGo.clean();
  496.             return;
  497.           }
  498.           else
  499.             target = "fromContentOuter.link";
  500.         }
  501.         else {
  502.           var tmpurl = url;
  503.           url = easyDragToGo.fixupSchemer(url);
  504.           url = easyDragToGo.SecurityCheckURL(url);
  505.           if (url)
  506.             target = "fromContentOuter.link";
  507.           else
  508.             url = tmpurl;
  509.         }
  510.       }
  511.       easyDragToGo.openURL(url, null, target);
  512.     }
  513.     else {
  514.       // Drag and Drop from Content area
  515.       var relX = aEvent.screenX - easyDragToGo.onStartEvent.screenX;
  516.       var relY = aEvent.screenY - easyDragToGo.onStartEvent.screenY;
  517.       // do nothing with drag distance less than 3px
  518.       if ( Math.abs(relX) < 3 && Math.abs(relY) < 3 ) {
  519.         easyDragToGo.clean();
  520.         return;
  521.       }
  522.  
  523.       var str, src;
  524.       var selectStr =  "";
  525.       var type = "STRING"; 
  526.       var target = "link";
  527.  
  528.       url = str = aXferData.data.replace( /\r\n/g, "\n").replace( /\r/g, "\n");
  529.  
  530.       try {
  531.         selectStr = easyDragToGo.SelectedText(easyDragToGo.onStartEvent.target);
  532.         selectStr = selectStr.replace( /\r\n/g, "\n").replace( /\r/g, "\n");
  533.       } catch(e) {}
  534.  
  535.       if (str != selectStr) {
  536.         var idx = str.indexOf("\n");
  537.         if (idx > 0) {
  538.           url = str.substr(0, idx);
  539.           str = str.substr(idx + 1);
  540.         }
  541.         if (str == selectStr)
  542.           url = str;
  543.         else if ( !(/\s|\n/.test(url)) && (/^([a-z]{2,7}:\/\/|mailto:|about:|javascript:)/i.test(url)) )
  544.           type = "URL";
  545.         else
  546.           url = selectStr;
  547.       }
  548.  
  549.       url = url.replace( /^[\s\n]+|[\s\n]+$/g, '' );
  550.  
  551.       if ( url && type == "URL" ) {
  552.  
  553.         src = url = easyDragToGo.SecurityCheckURL(url);
  554.  
  555.         if (sNode.nodeName == "IMG" || sNode.nodeName == "A" && /^\s*$/.test(sNode.textContent) && sNode.firstElementChild instanceof HTMLImageElement) {
  556.           try {src = sNode.src || sNode.firstElementChild.src;} catch(e) {}
  557.           target = "img";
  558.         }
  559.         else if (aEvent.ctrlKey) {
  560.           // as text with ctrlkey
  561.           var aNode = easyDragToGo.onStartEvent.target;
  562.           while (aNode && aNode.nodeName != "A") aNode = aNode.parentNode;
  563.           if (aNode && aNode.textContent) {
  564.             url = aNode.textContent;
  565.             target = "text";
  566.           }
  567.         }
  568.       }
  569.       else if (url) {
  570.         var tmpurl = url;
  571.         if (aEvent.ctrlKey) {
  572.           url = easyDragToGo.getForceURL(url)    // force convert to a url
  573.           url = easyDragToGo.SecurityCheckURL(url);
  574.           if (url)
  575.             target = "link";
  576.           else
  577.             url = tmpurl;
  578.         }
  579.         else if ( easyDragToGo.seemAsURL(url) ) { //seem as a url
  580.           url = easyDragToGo.fixupSchemer(url);
  581.           url = easyDragToGo.SecurityCheckURL(url);
  582.           if (!url) { // not a url, search it
  583.             url = tmpurl;
  584.             target = "text";
  585.           }
  586.         }
  587.         else         //it's a text string, so search it
  588.           target = "text";
  589.       }
  590.  
  591.       easyDragToGo.openURL(url, src, target, relX, relY);
  592.     }
  593.  
  594.     easyDragToGo.clean();
  595.   },
  596.  
  597.   getSupportedFlavours: function() {
  598.     var flavourSet = new FlavourSet();
  599.     flavourSet.appendFlavour("text/x-moz-url");
  600.     flavourSet.appendFlavour("text/unicode");
  601.     return flavourSet;
  602.   }
  603. };
  604.  
  605. window.addEventListener('load', easyDragToGo.onLoad, false);
  606.